package com.ruoyi.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.course.domain.ExamInvoice;
import com.ruoyi.course.vo.ExamInvoiceVo;
import com.ruoyi.course.mapper.ExamInvoiceMapper;
import com.ruoyi.course.service.IExamInvoiceService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 发票申请Service业务层处理
 *
 * @author Tellsea
 * @date 2025-10-14
 */
@Service
public class ExamInvoiceServiceImpl extends ServiceImpl<ExamInvoiceMapper, ExamInvoice> implements IExamInvoiceService {

    @Override
    public TableDataInfo<ExamInvoiceVo> queryList(ExamInvoiceVo entity) {
        return PageUtils.buildDataInfo(this.baseMapper.queryList(PageUtils.buildPage(), entity));
    }

    @Override
    public List<ExamInvoiceVo> queryAll(ExamInvoiceVo entity) {
        return this.baseMapper.queryList(entity);
    }

    @Override
    public ExamInvoiceVo queryById(Long id) {
        return this.baseMapper.queryById(id);
    }

    @Override
    public boolean existsByIdCardAndClassId(Long userId, Long classId) {
        LambdaQueryWrapper<ExamInvoice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ExamInvoice::getUserId, userId)
                   .eq(ExamInvoice::getClassId, classId)
                   .eq(ExamInvoice::getDeleteStatus, 1); // 只查询未删除的记录
        System.out.println(this.count(queryWrapper));
        return this.count(queryWrapper) > 0;
    }

    @Override
    public List<ExamInvoiceVo> queryMyInvoiceList(Long userId) {
        return this.baseMapper.queryMyInvoiceList(userId);
    }

    @Override
    public TableDataInfo<ExamInvoiceVo> queryMyInvoicePage(Long userId) {
        return PageUtils.buildDataInfo(this.baseMapper.queryMyInvoicePage(PageUtils.buildPage(), userId));
    }
}
